#ifndef CNFIELD_H_
#define CNFIELD_H_

#include "rectype.h"
#include "chararray.h"

namespace opsrc {
    namespace stdf {

        template <typename T /* Output Type, mainly std::string */,
        int L = -1 /* Length if -1, will be derived from reading the char buffer */>
        class CnField
        {
        public:
            CnField();
            CnField(char* buf, endian e);
            virtual ~CnField();

            T decode(char* buf);
            int getByteCount() const;

            T getData() const;

            int getTotalByteCount() const;

        private:
            int blen;
            T data;
            endian en;

        };

        // Specialization for B*n type
        // Specialization for CharArray
        // which is a series or string of Byte data
        template < int L>
		class CnField <CharArray, L>
        {
        public:
            CnField();
            CnField(char *p , endian e);
            virtual ~CnField();

            CharArray decode(char* buf);        // special handling
            int getByteCount() const;
            CharArray getData() const;

            int getTotalByteCount() const;

        private:
            CharArray data;
            int len;
            endian en;
        };

    }	// namespace stdf
}	// namesdpace opsrc


#endif /*CNFIELD_H_*/
